<script type="text/javascript">
$(function(){
	var content=""
	$.post("getAppKind",function(json){
		for(var i=0;i<json.length;i++){
			content=content+"<option value="+json[i].appFlag+">"+json[i].appName+"</option>"
		}
		$("#appByDeposit").html(content);
		$("#appByRepeal").html(content);
		
	},"json")
})
 //充值读卡 --------------------------------------------------
function readCardByDeposit(){
	var flag=qzsmkocx.activeCPU();
	if(flag) flag=qzsmkocx.GetSmkNo();//获取市民卡号
	var citizenCardNo="";
	$("input[type='text']").val("");//clean数据
	$("#buttonByRepeal").removeAttr("disabled");
	$("#buttonByDeposit").removeAttr("disabled");
	if(flag){
		citizenCardNo=qzsmkocx.GetRetValue().split(",")[0];
		$("input[name='citizenCardNo']").val(citizenCardNo);
		//通过市民卡号获取数据
		$.post("business/queryInfoByReadCard",{citizenCardNo:citizenCardNo},function(json){
			if(json.qVo!=null&&json.statusCode==DWZ.statusCode.ok){
				$("input[name='cardPName']").val(json.qVo.cardPName);
				$("input[name='cardPCode']").val(json.qVo.cardPCode);
				if(json.qVo.customerName!=null){
					$("input[name='customerName']").val(json.qVo.customerName);
					$("input[name='paperTypeName']").val(json.qVo.paperTypeName);
					$("input[name='paperType']").val(json.qVo.paperType);
					$("input[name='paperNo']").val(json.qVo.paperNo);
				}	
			}
			var list=json.appKinds;
			if(json.statusCode==DWZ.statusCode.ok){
				var content=""
				for(var i=0;i<list.length;i++){
					content=content+"<option value="+list[i].appFlag+">"+list[i].appName+"</option>"
				}
				$("#appByDeposit").html(content);
				$("#appByRepeal").html(content);
			}
			else if(json.statusCode==DWZ.statusCode.error){
				alertMsg.warn('卡未出售或无已开通的应用');
				$("#buttonByRepeal").attr("disabled",true);
				$("#buttonByDeposit").attr("disabled",true);
			}
		},"json");
	}else{
		checkError(getError())
	}	
  };
  //银行联名卡判断卡片是否被激活
  function checkIsUseing(app){
	  if(app=="3F01"){
			f=get3F01AppInfo();
			if(f){
				var value=getValue().split(",")[7];
				$("input[name='useDate']").val(cardDateToHtml(value))
				if(value=="00000000"){
					alertMsg.warn('请激活此卡片的当前应用');
					$("#buttonByuseDate").attr("hidden",false)
					$("#buttonByDeposit").attr("disabled",true);
				}
			}else{
				checkError(getError())
			}
		}
  }
  //获取余额----------------------------------------------
  function getBalanceByEpTypeDeposit(app,epEd){
  	if(epEd==""){
  		alertMsg.warn('请选择钱包类型');
  		return false;
  	}
	var f= getBalance(app,epEd);
	if(f==false){
		checkError(getError())
	}
	if(f){
		var value=qzsmkocx.GetRetValue();
		$("input[name='oldMoney']").val(value.split(",")[0])
		$("input[name='effectiveDate']").val(cardDateToHtml(value.split(",")[1]))
	}
	checkIsUseing(app);
	
	$("input[name='newMoney']").val("")
  }
  //自行车应用
  var vipno, vipcardsn, balance;
 function getBalanceByAppDeposit(app,epEd){
	 var citizenCardNo=$("input[name='citizenCardNo']").val();
	 if(citizenCardNo==""){
		 alertMsg.warn('请先读卡');
		 return false;
	 }
	 if(app=="M1BK"){
		 var content="<option value='33'>自行车账户</option>"
		 $("#epOrEdByDeposit").html(content)
		 $.post("business/getBikeBlance",{citizenCardNo:citizenCardNo},function(json){
			 if(json.statusCode==DWZ.statusCode.error){
				 navTabAjaxDone(json)
			 }else{
				 if(json.head.rsltcode=="0000"){
					 var oldblance=json.body.balance;
					 vipno=json.body.vipno;
					 vipcardsn=json.body.vipcardsn;
					 balance=oldblance
					 $("input[name='oldMoney']").val(parseInt(oldblance)==0?0:parseInt(oldblance)/100) 
					 $("input[name='effectiveDate']").val("自行车无有效期")
				 }else{
					 checkBikeError(json.head.rsltcode)
				 }	
			 }
			 
		 },"json")
	 }else{
		 var content="<option value=''>请选择钱包</option><option value='02'>电子钱包</option><option value='01'>电子存折</option>"
	 	 $("#epOrEdByDeposit").html(content)
		 if(epEd==""){
	  		alertMsg.warn('请选择钱包类型');
	  		return false;
	  	}
	 	var f= getBalance(app,epEd);
		if(!f){
			checkError(getError())	
		}
		if(f){
			var value=qzsmkocx.GetRetValue();
			$("input[name='oldMoney']").val(value.split(",")[0])
			$("input[name='effectiveDate']").val(cardDateToHtml(value.split(",")[1]))
		}
		checkIsUseing(app);
		
	 }		
	$("input[name='newMoney']").val("")
 }

 //激活卡片（启用日期和应用类型标识）
 function activedCardapp(adf){
	 var idate=writeDate(Date.now())
	 var updateInfo="key_appid,02|key_sdate,"+idate;
	 var b=updateBaseInfo(adf, updateInfo);
	 if(b){
		 checkIsUseing(adf)
		 $("#buttonByuseDate").attr("hidden",true);
		 $("#buttonByDeposit").removeAttr("disabled");
	 }else{
		 checkError(getError())	
	 }
	 
 }
 //充值金额不能大于1000元-----------------------------------------------------------------
 function checkBlance(adf,epEd,money){
	 var citizenCardNo=$("input[name='citizenCardNo']").val();
	 var oldMoney=$("input[name='oldMoney']").val();
	 var blance=parseInt(oldMoney)+parseInt(money);
	 var depositType=$("#epOrEdByDeposit").find("option:selected").text()
	 if(citizenCardNo==""){
			 alertMsg.warn("请先读卡");
			 return false;
	 }
	 if(epEd==""){
	  		alertMsg.warn('请选择钱包类型');
	  		return false;
	  	}
	 alertMsg.confirm("充值卡号："+citizenCardNo+",充值类型："+depositType+",充值金额："+money, {
  		okCall: function(){
  			 if(blance>=1000){
  				 alertMsg.warn("您的金额以大于1000，无法充值");
  				 return false;
  			 }
  			 if(adf=="M1BK"){
  				 var param={citizenCardNo:citizenCardNo,recharge:money,vipno:vipno,vipcardsn:vipcardsn,balance:balance}
  				 $.post("business/bikeDeposit",param,function(json){
  					if(json.statusCode==DWZ.statusCode.ok){
  						alertMsg.correct(json.message);
  					}else{
  						navTabAjaxDone(json)
  					}
  				 },"json")
  			 }else{
  				pay(adf,epEd,money); 
  			 }
  			 
  		}
  	});	
	 
 }
 

 function checkRechargeCancel(id,epEd,money){
	 var citizenCardNo=$("input[name='citizenCardNo']").val();
	 var repealMoney=$("input[name='repealMoney']").val();
	 var repealType=$("#epOrEdByRepeal").find("option:selected").text();
	 if(citizenCardNo==""){
		 alertMsg.warn("请先读卡");
		 return false;
	 }
	 if(epEd==""){
  		alertMsg.warn('请选择钱包类型');
  		return false;
  	}
	 alertMsg.confirm("充值撤销卡号："+citizenCardNo+",撤销钱包类型："+repealType+",撤销金额："+repealMoney, {
	  		okCall: function(){
	  			var blance;
  				var f= getBalance(id,epEd);
  				if(!f){
  					checkError(getError());	
  					return false;
  				}
  				if(f){
  					 blance=qzsmkocx.GetRetValue().split(",")[0];
		 		}	  			 
  				if(parseInt(money)>parseInt(blance)){
  					alertMsg.warn("余额不足,请确认撤销金额!");
  					 return false;
  				}
  				if(id=="M1BK"){
  					$.post("business/bikeRechargeCancel",{citizenCardNo:citizenCardNo},function(json){
  						if(json.statusCode==DWZ.statusCode.ok){
  	  						alertMsg.correct(json.message);
  	  					}else{
  	  						navTabAjaxDone(json)
  	  					}
  					},"json")
  				}else{
  					rechargeCancel(id,epEd,money);
  				}
  				
	  		}
	  	});
 }
 function printVoucher(){
 		var options=new Object();
 		options.max=true;
 		$.pdialog.open("printCredentials/toHairpinPdfView","infos", "充值凭证",options);
 		$("#depositBefore").hide();
 }
</script> 
<div class="pageContent">   
         <div class="pageFormContent" layoutH="136">
         <fieldset>
			<legend>读卡</legend>
        		<p>
				<label>市民卡号：</label> 
				<input name="citizenCardNo" type="text" readonly="readonly"/>&nbsp;&nbsp;&nbsp;&nbsp;
				<input type="button" class="newButton"value="读卡" onclick="readCardByDeposit()"/> 
				</p>
			</fieldset>
			<fieldset>
			<legend>基本信息</legend>
						
			
			<p>
				<label>卡产品：</label>
				<input name="cardPName" type="text"  value="" readonly="readonly"/>
				<input name="cardPCode" type="hidden">
			</P>
			<p>
				<label>姓名：</label>
				<input name="customerName" type="text"  value="" readonly="readonly"/>
				
			</P>
			<p>
				<label>证件类型：</label>
				<input name="paperTypeName" type="text"  value="" readonly="readonly"/>
				<input name="paperType" type="hidden">
			</P>
			<p>
				<label>证件号码：</label>
				<input name="paperNo" type="text" value="" readonly="readonly"/>
				
			</P>
			
	
		</fieldset>
		<fieldset>
			<legend>交易区</legend>
			<p>
				<label>选择应用：</label>
				<select id="appByDeposit" onchange="getBalanceByAppDeposit($('#appByDeposit').val(),$('#epOrEdByDeposit').val())">
					<option value="3F01">3F01</option>
				    <option value="3F02">3F02</option>
				    <option value="3F10">3F10</option>
				    <option value="9A00">9A00</option>
                </select>                     
			</P> 
			<p>
				<label>充值类型：</label>
				<select id="epOrEdByDeposit" onchange="getBalanceByEpTypeDeposit($('#appByDeposit').val(),$('#epOrEdByDeposit').val())">
					<option value="">请选择钱包</option>
					<option value="02">电子钱包</option>
				    <option value="01">电子存折</option>
                </select>
			</P>
			
			<p>
				<label>有效日期：</label>
				<input  name="effectiveDate" type="text" value="" readonly="readonly"/>
			</P>
			<p>
				<label>启用日期：</label>
				<input  name="useDate" type="text" value="" readonly="readonly"/>&nbsp;&nbsp;&nbsp;&nbsp;
                <input type="button" id="buttonByuseDate" class="newButton" value="应用激活" onclick="activedCardapp($('#appByDeposit').val())" hidden="true">
			</P>
			
			<p>
				<label>充值前金额：</label>
				<input name="oldMoney" type="text" value="" readonly="readonly"/>
			</P>
			 
			<p>
				<label>充值金额(元)：</label>
				<select id="deposit" name="recharge">
					<option value="30">30</option>
				    <option value="50">50</option>
                    <option value="100">100</option>
                    <option value="500">500</option>
                </select>&nbsp;&nbsp;&nbsp;&nbsp;
                <input type="button" id="buttonByDeposit" class="newButton" value="充值" onclick="return checkBlance($('#appByDeposit').val(),$('#epOrEdByDeposit').val(),$('#deposit').val())"> 
                
			</P>
			<p>
				<label>充值后金额：</label>
				<input name="newMoney" type="text" value="" readonly="readonly"/>
			</P>
			<p>
	        <a id="depositBefore" class="button"  href="#"  style="display:none" onclick="printVoucher()"><span >打印凭证</span></a><br /><br />
		    </p>
		 </fieldset>
		 <!-- 充值撤销 -->
		 <fieldset>
			<legend>充值撤销</legend>
			<p>
				<label>选择应用：</label>
				<select id="appByRepeal">
					<option value="3F01">3F01</option>
				    <option value="3F02">3F02</option>
				    <option value="3F10">3F10</option>
				    <option value="9A00">9A00</option>
                </select>
			</P>
			<p>
				<label>撤销类型：</label>
				<select id="epOrEdByRepeal">
					<option value="02">电子钱包</option>
				    <option value="01">电子存折</option>
                </select>
			</P>
			<p>
				<label>撤销金额(元)：</label>
				<input  id="repealMoney" name="repealMoney" type="text">
                &nbsp;&nbsp;&nbsp;&nbsp;
                <input type="button" id="buttonByRepeal" class="newButton"value="确认" onclick="return checkRechargeCancel($('#appByRepeal').val(),$('#epOrEdByRepeal').val(),$('#repealMoney').val());"> 
			</P>
			 
		 </fieldset>
		 
	</div>
	</div>
</div>